Import data

df_homo <- do.call(rbind, lapply(Sys.glob("../control_group/data/coop_ratio/*.csv"), read_csv))
df_coop_max <- do.call(rbind, lapply(Sys.glob("../*max/data/coop_ratio/*.csv"), read_csv))
#df_coop_min <- do.call(rbind, lapply(Sys.glob("../*min/data/coop_ratio/*.csv"), read_csv))
full <- df_homo %>%
  rbind(df_coop_max)
rm(df_homo,df_coop_max)

Cooperation Ratio

Analysis of cooperation ratio

full %>%
  group_by(tournament_type, seed) %>%
  summarise(mean_coop = mean(coop_ratio),
            sd_coop = sd(coop_ratio)) %>%
  ggplot(aes(x = as.factor(tournament_type), y = mean_coop, fill = tournament_type)) +
  geom_bar(stat="identity") +
  geom_errorbar(aes(ymin = mean_coop-sd_coop, ymax = mean_coop + sd_coop), width = .7) +
  facet_wrap(~seed) +
  coord_flip() +
  scale_fill_grey(guide = F) +
  labs(title = "Mean cooperation ratio and standard deviation per tournament type, facetted by seed",
       y = "cooperatio ratio",
       x = " ")

full %>%
  group_by(tournament_type, seed) %>%
  summarise(mean_coop = mean(coop_ratio),
            sd_coop = sd(coop_ratio)) %>%
  ggplot(aes(x = as.factor(seed), y = mean_coop, fill = tournament_type)) +
    geom_bar(stat="identity") +
    geom_errorbar(aes(ymin = mean_coop-sd_coop, ymax = mean_coop + sd_coop), width = .7) +
    facet_wrap(~tournament_type) +
    coord_flip() +
    scale_fill_grey(guide = F) +
    labs(title = "Mean cooperation ratio and standard deviation per seed, facetted by tournament type",
         y = "cooperatio ratio",
         x = " ")

Comparing the control group with heterogenous groups

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("pareto_dr_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("pareto_m_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("pareto_mdr_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("hetero_dr_sd_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("hetero_m_sd_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

full %>%
  group_by(seed, tournament_type) %>%
  mutate(round = row_number()) %>%
  ungroup() %>%
  filter(str_detect(tournament_type, c("hetero_mdr_sd_max", "homogenous"))) %>%
  ggplot(aes(round, coop_ratio, color = tournament_type)) +
  geom_smooth(color = "black") +
  #geom_point(color = "black") +
  facet_wrap(tournament_type~seed) +
  scale_color_grey(guide = F) 

Stability

Data Prep

# x <- Sys.glob("../*min/data/outliers/*outlier_counts.csv")
# 
# for(i in x){
# 
#   tournament_type <- str_remove(i, "../") %>%
#     str_remove("/data/outliers/.*")
#   seed <- str_remove(i, ".*outliers/") %>%
#     str_remove("_outlier_counts.csv")
#   save_name <- paste0("../", tournament_type, "/data/outliers/", seed, "_harmonized.csv")
# 
#   df <- read_csv(i) %>%
#     select(S.D., Counts) %>%
#     mutate(seed = seed,
#            tournament_type = tournament_type)
#   write_csv(df, paste0(save_name))
#
#}

Data import

Comparison of All Groups

# lm model
# lm_model <- df_outliers_full %>%
#     group_by(as.factor(tournament_type)) %>%
#     do({
#       mod = lm(Counts ~ S.D., data = .)
#       data.frame(Intercept = coef(mod)[1],
#                  Slope = coef(mod)[2],
#                  R2 = summary(mod)$r.squared)
#     })

my_formula <- y ~ x

df_outliers_full %>%
  ggplot() +
  geom_point(aes(S.D., Counts, color = as.factor(seed))) +
  geom_smooth(aes(S.D., Counts), color = "black") +
  facet_wrap(~tournament_type) +
      scale_color_grey(guide = F) +
  labs(title = "Smooth function applied to count of outliers on standard deviation",
       x = "standard deviation",
       y = "count of outliers")

df_outliers_full %>%
  select(x = S.D., y = Counts, tournament_type, seed) %>%
    ggplot(aes(x = x, y = y)) +
      geom_point(aes(x, y, color = as.factor(seed))) +
      geom_smooth(method = "lm", color = "black", se=FALSE, formula = my_formula) +
      stat_poly_eq(formula = my_formula, 
                   aes(label = paste(..eq.label.., sep = "~~~")), 
                   parse = TRUE,
                   label.x = 2) +         
      facet_wrap(~tournament_type) +
            scale_color_grey(guide = F) +
  labs(title = "Linear function applied to count of outliers on standard deviation",
       x = "standard deviation",
       y = "count of outliers")

df_outliers_full %>%
  filter(S.D. <= 1.5) %>%
  select(x = S.D., y = Counts, tournament_type, seed) %>%
    ggplot(aes(x = x, y = y)) +
      geom_point(aes(x, y, color = as.factor(seed))) +
      geom_smooth(method = "lm", color = "black", se=FALSE, formula = my_formula) +
      stat_poly_eq(formula = my_formula, 
                   aes(label = paste(..eq.label.., sep = "~~~")), 
                   parse = TRUE,
                   label.x = 2) +         
      facet_wrap(~tournament_type) +
            scale_color_grey(guide = F) +
  labs(title = "Linear function applied to count of outliers on standard deviation",
       subtitle = "Range of S.D. limited from 0 to 1.5",
       x = "standard deviation",
       y = "count of outliers")

df_outliers_full %>%
  filter(S.D. >= 1.5) %>%
  select(x = S.D., y = Counts, tournament_type, seed) %>%
    ggplot(aes(x = x, y = y)) +
      geom_point(aes(x, y, color = as.factor(seed))) +
      geom_smooth(method = "lm", color = "black", se=FALSE, formula = my_formula) +
      stat_poly_eq(formula = my_formula, 
                   aes(label = paste(..eq.label.., sep = "~~~")), 
                   parse = TRUE,
                   label.x = 2) +         
      facet_wrap(~tournament_type) +
            scale_color_grey(guide = F) +
  labs(title = "Linear function applied to count of outliers on standard deviation",
       subtitle = "Range of S.D. limited from 1.5 to 3",
       x = "standard deviation",
       y = "count of outliers")